import Mock from "mockjs";

let { data } = Mock.mock({
  "data|120": [
    {
      "id|+1": 1,
      name: "@cname",
      teacher: "@cname",
      Ctext: "@cparagraph(1,1,3)",
      "time|1571079761083-1671079761083": 1577836800000,
    },
  ],
});

// 列表接口，分页，搜索
Mock.mock("/api/pos/list", "post", (options) => {
  const {pageSize , currentPage}=JSON.parse(options.body);
  if(pageSize && currentPage){
    const result = data.slice((currentPage -1) * pageSize, currentPage * pageSize)
  return {
    statue:0,
    result:result,
    count :data.length
  }
  }else{
    return {
      status:1,
      result:"参数错误"
    }
  }
  
});


// 删除接口
Mock.mock("/api/pos/del", "post", (options) => {
  const { id } = JSON.parse(options.body);
 console.log(id);
 for (let i = 0; i < id.length; i++) { //遍历数组
        for (let j = 0; j < data.length; j++) {
            if (id[i] === data[j].id) {
              data = data.filter((item: any) => item.id !== data[j].id);
            }
        }
    }
});

//传输接口
Mock.mock("/api/pos/del", "get", (options) => {
  data.push(options);
  return data;
});

export default Mock;
